import menus from './menus'

/**
 * 模拟添加接口
 */
export const add = (params, time = 0) => {
  console.log(params)
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      resolve({
        code: '0000',
        message: '添加成功'
      })
    }, time)
  })
}

/**
 * 模拟删除接口
 */
export const remove = (params, time = 0) => {
  console.log(params)
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      resolve({
        code: '0000',
        message: '删除成功'
      })
    }, time)
  })
}

/**
 * 模拟修改接口
 */
export const update = (params, time = 0) => {
  console.log(params)
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      resolve({
        code: '0000',
        message: '修改成功'
      })
    }, time)
  })
}

/**
 * 模拟获取接口
 */
export const getData = (params, data, time = 0) => {
  console.log(params)
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      resolve({
        code: '0000',
        message: '获取成功',
        data
      })
    }, time)
  })
}

/**
 * 模拟获取接口
 */
export const getListPage = (params, data, time = 0) => {
  // 模拟表格数据
  const tableData = {
    current: 1,
    pages: 1,
    records: [
      {}
    ],
    size: 20,
    total: 1
  }
  data = data || tableData
  return getData(params, data, time)
}

/**
 * 模拟获取接口
 */
export const getListAll = (params, data = [{}], time = 0) => {
  return getData(params, data, time)
}

/**
 * 模拟获取接口
 */
export const getDetail = (params, data = {}, time = 0) => {
  return getData(params, data, time)
}

/**
 * 模拟登录接口
 */
export const login = (params, time = 0) => {
  console.log(params)
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      resolve({
        code: '0000',
        message: '登录成功',
        data: {
          uuid: 'aabbccddeeff',
          loginName: 'admin',
          userName: 'admin',
          token: 123456,
          roleName: '管理员',
          status: 2
        }
      })
    }, time)
  })
}

/**
 * 模拟登出接口
 */
export const logout = (params, time = 0) => {
  console.log(params)
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      resolve({
        code: '0000',
        message: '登出成功',
      })
    }, time)
  })
}

/**
 * 模拟获取用户信息
 */
export const getUserInfo = (params, time = 0) => {
  console.log(params)
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      resolve({
        code: '0000',
        message: '获取用户信息成功',
        data: {
          uuid: 'aabbccddeeff',
          loginName: 'admin',
          userName: 'admin',
          token: 123456,
          roleName: '管理员',
          status: 2
        }
      })
    }, time)
  })
}

/**
 * 模拟获取菜单
 */
export const getMenus = (params, time = 0) => {
  console.log(params)
  return new Promise(function (resolve, reject) {
    setTimeout(() => {
      resolve({
        code: '0000',
        message: '获取菜单成功',
        data: menus
      })
    }, time)
  })
}
